package cn.skyclass.controls
{
	import mx.containers.Canvas;
	import flash.events.MouseEvent;
	import mx.core.ScrollPolicy;
	
	/**
	 * 基本的 IListItem 实现，提供常用的 item 样式
	 */
	[Bindable]
	public class ListItemCanvas extends Canvas implements IListItem
	{
		public function ListItemCanvas(){
			this.horizontalScrollPolicy = ScrollPolicy.OFF;
			this.verticalScrollPolicy = ScrollPolicy.OFF;
			this.buttonMode = true;
			
			this.addEventListener(MouseEvent.ROLL_OVER, this.rollOverHandler);
			this.addEventListener(MouseEvent.ROLL_OUT, this.rollOutHandler);
			this.addEventListener(MouseEvent.CLICK, this.clickHandler);
		}
		
		protected function rollOverHandler(e:MouseEvent):void{
			this.showBorder = true;
		}
		
		protected function rollOutHandler(e:MouseEvent):void{
			if(!this.selected){
				this.showBorder = false;
			}
		}
		
		protected function clickHandler(e:MouseEvent):void{
			// do nothing
		}
		
		/**
		 * 显示控件的边框
		 */
		private var _showBorder:Boolean;
		public function get showBorder():Boolean{
			return this._showBorder;
		}
		public function set showBorder(value:Boolean):void{
			this._showBorder = value;				
            setStyle("borderStyle", value ? "solid" : "none");
           	setStyle("dropShadowEnabled", value);	
		}
				
				
		private var _selected:Boolean;
		public function get selected():Boolean{
			return this._selected;
		}
		public function set selected(value:Boolean):void{
			this._selected = value;			
			this.showBorder = value;
		}		
		
		
		/**
		 * 作为数据显示的数据源
		 */
		private var _datasource:Object;
		public function get datasource():Object{
			return this._datasource;
		}
		public function set datasource(value:Object):void{
			this._datasource = value;
		}
		
		/**
		 * 初始化此控件的内容
		 */
		public function init():void{
			// do nothing
		}
	}
}